-- grytole@gmail.com 08-Jul-2012

print('Running image test')

isok, errmsg = sdl.init( {w = 720, h = 480, bpp = 32}, 'Image test' )
if isok == false then
  print( 'SDL init failed:', errmsg )
  os.exit()
end

isok, retval = sdl.fill( {w = 620, h = 380}, {r = 64, g = 64, b = 64, a = 64} )
if isok == false then
  print( 'Rect rendering failed:', retval )
  os.exit()
else
  rect = retval
end

isok, retval = sdl.image( './examples/image/tst.png' )
if isok == false then
  print( 'Image load failed:', retval )
  os.exit()
else
  image = retval
end

isok, errmsg = sdl.blit( rect, {x = 0, y = 0, w = rect.w, h = rect.h}, nil, {x = 50, y = 50} )
if isok == false then
  print( 'Rect blit failed:', errmsg )
  os.exit()
end

isok, errmsg = sdl.blit( image, {x = 0, y = 0, w = image.w, h = image.h}, nil, {x = 310, y = 190} )
if isok == false then
  print( 'Image blit failed:', errmsg )
  os.exit()
end

isok, errmsg = sdl.flip()
if isok == false then
  print( 'Buffers flip failed:', errmsg )
  os.exit()
end

isok, errmsg = sdl.delay(10000)
if isok == false then
  print( 'Delay failed:', errmsg )
  os.exit()
end

isok, errmsg = sdl.quit()
if isok == false then
  print( 'SDL quit failed:', errmsg )
  os.exit()
end

print('Done')

-- eof
